package auth

import (
	"beergo/app/admin/controller"
	"beergo/app/admin/service"
	"beergo/conf/const/code"
	"beergo/lib/tool"
	"github.com/beego/beego/v2/server/web"
)

type AuthController struct {
	controller.AdminBaseController
}

func init() {
	web.Router("/admin/GetMenu",&AuthController{},"*:GetMenuAction")
}

func (this *AuthController) Prepare() {
	adminUser := this.GetUser()
	if adminUser.Id == 0 {
		this.ReturnError(code.ErrorAuth,"请登录后再操作","1")
	}
}
func (this *AuthController) GetMenuAction(){
	user := this.GetUser()
	permissions,ids := service.GetUserMenu(&user)
	this.ReturnSuccess("OK", tool.StringKeyMap{
		"menu":permissions,
		"users":ids,
	})
}
